package com.mbt.deal.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mbt.deal.R;
import com.mbt.deal.R2;
import com.mbt.deal.bean.OrderListBean;
import com.mbt.deal.ui.adapter.OrderViewPagerAdapter;
import com.mbt.deal.ui.contract.OrderListContract;
import com.mbt.deal.ui.model.TransActionModel;
import com.mbt.deal.ui.model.TransActionOrderModel;
import com.mbt.deal.ui.presenter.OrderHistoryPresenter;
import com.mbt.deal.ui.presenter.TransActionListPresenter;
import com.mbt.deal.ui.widgets.XTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 创建日期：2018/8/15 on 8:18
 * 描述:
 * 作者:王甜
 */
public class OrderListActivity extends BaseActivity implements ViewPager.OnPageChangeListener {

    @BindView(R2.id.ll_back)
    LinearLayout llBack;
    @BindView(R2.id.txt_title)
    TextView txtTitle;
    @BindView(R2.id.ll_right_menu)
    LinearLayout llRightMenu;
    @BindView(R2.id.txt_wait_deal)
    TextView txtWaitDeal;
    @BindView(R2.id.txt_order_dealing)
    XTextView txtOrderDealing;
    @BindView(R2.id.txt_order_finsh)
    TextView txtOrderFinsh;
    @BindView(R2.id.viewpager)
    ViewPager viewPager;

    OrderViewPagerAdapter mOrderPagerAdapter;

    String orderStatus = "";//订单状态

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_list);
        ButterKnife.bind(this);

        initData();
    }

    private void initData() {
        mOrderPagerAdapter = new OrderViewPagerAdapter(act);
        viewPager.setAdapter(mOrderPagerAdapter);
        setSelected(0);
        txtTitle.setText("订单");
        llRightMenu.setVisibility(View.GONE);
        viewPager.setCurrentItem(0);
        viewPager.setOffscreenPageLimit(3);
        viewPager.addOnPageChangeListener(this);

    }

    @OnClick({R2.id.ll_back, R2.id.ll_right_menu, R2.id.txt_wait_deal, R2.id.txt_order_dealing, R2.id.txt_order_finsh})
    public void onViewClicked(View view) {
        int i = view.getId();
        if (i == R.id.ll_back) {
            finish();
        } else if (i == R.id.ll_right_menu) {

        } else if (i == R.id.txt_wait_deal) {
            setSelected(0);
        } else if (i == R.id.txt_order_dealing) {
            setSelected(1);
        } else if (i == R.id.txt_order_finsh) {
            setSelected(2);
        }
    }

    /**
     * 设置选中
     *
     * @param type 0待处理1进行中2已完成
     */
    int type = 0;

    private void setSelected(int type) {
        this.type = type;
        switch (type) {
            case 0:
                txtWaitDeal.setSelected(true);
                txtOrderDealing.setSelected(false);
                txtOrderFinsh.setSelected(false);
                orderStatus = "3101";
                break;
            case 1:
                txtWaitDeal.setSelected(false);
                txtOrderDealing.setSelected(true);
                txtOrderFinsh.setSelected(false);
                orderStatus = "3102";
                break;
            case 2:
                txtWaitDeal.setSelected(false);
                txtOrderDealing.setSelected(false);
                txtOrderFinsh.setSelected(true);
                orderStatus = "3104";
                break;
        }

        viewPager.setCurrentItem(type);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        setSelected(position);
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
